package com.controller;

import com.alipay.api.AlipayApiException;
import com.pojo.requestjson.AddSalesProductDetailRequestJson;
import com.pojo.requestjson.ProductList;
import com.pojo.requestjson.ProductOrderJson;
import com.pojo.sales.ProductOrder;
import com.service.iter.IProductOrderService;
import com.service.iter.sales.IZfbService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


/**
 * 产品订单控制器
 *
 * @author admin
 * @date 2023/06/20
 */
@RestController
@RequestMapping("product/")
public class ProductOrderController {
    @Autowired
    private IZfbService zfbService;
    /**
     * 产品订单服务
     */
    @Autowired
    private IProductOrderService iproductOrderService;


    /**
     * 得到产品订单数据
     *
     * @return {@link List}<{@link ProductOrder}>
     */
    @GetMapping("getProductOrder")
    public List<ProductOrder> getProductOrder() {
        return iproductOrderService.QueryAll();
    }

    /**
     * 查询顺序
     *
     * @param requestJson 请求json
     * @return {@link Res}
     */
    @GetMapping("queryOrder")
    public Res queryOrder(String requestJson){
        return zfbService.queryOrder(requestJson);
    }

    /**
     * 检查
     *
     * @param
     * @return {@link Res}
     */
    @PostMapping("Checkout")
    @ResponseBody
    public Res Checkout(@RequestBody ProductOrderJson request) {

        HashMap<String, String> map = iproductOrderService.CheckOut(request.getId(),request.getSizeId());
        return new Res(null,Integer.parseInt(map.get("code")) ,map.get("msg"));
    }

    @PostMapping("UpdateState/{id}")
    @ResponseBody
    public Res UpdateStates(@PathVariable Long id) {
        HashMap<Object, Object> map = iproductOrderService.UpdateStatus(id);
        System.out.println(map);
             return new Res(null, Integer.parseInt(map.get("code").toString()), (String) map.get("msg"));
    }

}
